package com.bailugansan.efficiencyboard.utils;

import java.text.Format;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author BailuGansan
 */
public class DateUtils {

    private static final String FORMAT = "yyyy-MM-dd HH:mm:ss";
    private static SimpleDateFormat sdf = new SimpleDateFormat(FORMAT);

    public static String long2String(Long time){
        Date date = new Date(time);
        date.setMonth(date.getMonth()-1);
        String format = sdf.format(date);
        return format;
    }

    public static Long string2Long(String format){
        Date date = null;
        try {
            date = sdf.parse(format);
            date.setMonth(date.getMonth()+1);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return date != null ? date.getTime() : null;
    }


    public static boolean isExp(String time){
        Date date = new Date();
        Long cur = DateUtils.string2Long(sdf.format(date));
        Long prev = DateUtils.string2Long(time);

        return cur - prev < 0;
    }



}
